package com.yuanqi.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuanqi.pojo.Customer;
import com.yuanqi.service.CustomerService;
import com.yuanqi.mapper.CustomerMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @author LENOVO
* @description 针对表【customer(客户)】的数据库操作Service实现
* @createDate 2025-08-28 15:22:38
*/
@Service
public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer>
    implements CustomerService{
    @Resource
    private CustomerMapper customerMapper;

    @Override
    public Object pageWithAssoc(Integer pageNo, Integer pageSize, String customerName, Integer status, Long ownerEmployeeId) {
        Page<Map<String, Object>> page = new Page<>(pageNo == null ? 1 : pageNo, pageSize == null ? 10 : pageSize);
        Map<String, Object> params = new HashMap<>();
        params.put("customerName", customerName);
        params.put("status", status);
        // 与当前库结构保持一致，不使用负责人过滤
        // 使用自定义SQL，MyBatis-Plus分页需要在XML中适配（方言自动）
        List<Map<String, Object>> records = customerMapper.selectPageWithAssoc(page, params);
        Map<String, Object> result = new HashMap<>();
        result.put("records", records);
        result.put("total", page.getTotal());
        result.put("current", page.getCurrent());
        result.put("size", page.getSize());
        return result;
    }
}




